Aim

  • Learning how to graph/plot in R and basic customizations.

Graphics

One of the main reasons data analysts turn to R is for its strong graphic capabilities.

Creating a Graph

The plot( ) function opens a graph window and plots weight vs. miles per gallon. The next line of code adds a regression line to this graph. The final line adds a title.

Saving Graphs

You can save the graph in a variety of formats from the menu File -> Save As.

You can also save the graph via code using one of the following functions.

Function Output to
pdf(“mygraph.pdf”) pdf file
win.metafile(“mygraph.wmf”) windows metafile
png(“mygraph.png”) png file
jpeg(“mygraph.jpg”) jpeg file
bmp(“mygraph.bmp”) bmp file
postscript(“mygraph.ps”) postscript file

Built-in plots functions

Few ploting functions comes built-in when R installed. These can help do diffrent type of plots. Such as * Scater Plots * Dot Plots * Bar Plots * Pie Charts * Box Plots

Box Plots

Notched Boxplot

## Warning in bxp(list(stats = structure(c(8.2, 9.7, 12.25, 16.5, 21.5, 4.2, :
## some notches went outside hinges ('box'): maybe set notch=FALSE

Customization

Graphical parameters describes how to change a graph’s symbols, fonts, colors, and lines. Axes and text describe how to customize a graph’s axes, add reference lines, text annotations and a legend. Combining plots describes how to organize multiple plots into a single graph.

## The following objects are masked from mtcars (pos = 3):
## 
##     am, carb, cyl, disp, drat, gear, hp, mpg, qsec, vs, wt

Advance Ploting

Refer the follwing link - https://www.statmethods.net/advgraphs/index.html

Key Points

  • Legends of any plot can be made using legend() just after the plot is made.
 

Created and Maintained by Sangram Keshari Sahu
Licensed under CC-BY 4.0
Source Code At GitHub
Template used from Rmdplates package